import {logger} from "@/main/log.js";
import Store from "electron-store";
import {lcuServerManager} from "@/main/lcu/LcuServierManager.js";
import store, {store_field_lcu_certificate} from "@/main/store/store.js";
import './ipcHandlers.js'
import {createMainWindow, createDynamicWindow} from './windowLoad.js'
import './update/autoUpdater.js';

const {app} = require('electron')

Store.initRenderer();

// 在应用准备就绪时调用函数
app.whenReady().then(() => {
    //初始化lcu服务
    lcuServerManager.init(false);
    createMainWindow();
    // createDynamicWindow();
})


//启动的时候要做的动作
const singleLock = app.requestSingleInstanceLock()
if (!singleLock) {
    logger.warn("当前APP存在多个实例，退出！！");
    app.quit();
}

//关闭网页安全警告
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
//*****app监听的事件*******
//允许不安全的证书 (支持https接口）
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
    event.preventDefault();
    callback(true); // 允许不安全的证书（仅限开发！）
});


app.on('quit', () => {
    //清除store存储的凭证信息
    store.delete(store_field_lcu_certificate);
    if (lcuServerManager.ws) {
        lcuServerManager.ws.close();
    }
    if (lcuServerManager.httpProxyServer) {
        lcuServerManager.httpProxyServer.close();
    }
})


